home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / other / inet2sim / inet2sim.c < prev    next >
C/C++ Source or Header  |  1991-01-28  |  3KB  |  154 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "net.h"
  4. #include "globals.h"
  5.  
  6.  
  7.     /* stuff needed by irsim modules (not used by this program) */
  8. public    FILE    *logfile = NULL;
  9. public    double    StackCap( t )    tptr  t;        { return 0; }
  10. public    void    init_listTbl()                {}
  11.  
  12.  
  13. public    int    do_sim_cap = TRUE;
  14. public    int    two_term_caps = FALSE;
  15. public    int    do_thresholds = TRUE;
  16. public    int    do_delays = TRUE;
  17. public    int    use_GND = FALSE;
  18. private    int    short_file = FALSE;
  19.  
  20.  
  21. private    char    *sim_file = NULL;
  22. private    char    *inet_file = NULL;
  23. private    void    sort_node_names();
  24.  
  25.  
  26. main( argc, argv )
  27.   int   argc;
  28.   char  *argv[];
  29.   {
  30.     FILE  *fin, *fout;
  31.     int   i;
  32.  
  33.     for( i = 1; i < argc; i++ )
  34.       {
  35.     if( argv[i][0] == '-' )
  36.       {
  37.         switch( argv[i][1] )
  38.           {
  39.         case 'C' :    do_sim_cap = FALSE;    break;
  40.         case '2' :    two_term_caps = TRUE;    break;
  41.         case 'T' :    do_thresholds = FALSE;    break;
  42.         case 'D' :    do_delays = FALSE;    break;
  43.         case 'G' :    use_GND = TRUE;        break;
  44.         case 'c' :    short_file = TRUE;    break;
  45.         case 'o' :
  46.             if( ++i < argc )
  47.             sim_file = argv[i];
  48.             else
  49.             Usage();
  50.             break;
  51.         default :
  52.             (void) fprintf( stderr, "Unknown switch %s\n", argv[i] );
  53.             Usage();
  54.           }
  55.       }
  56.     else
  57.       {
  58.         inet_file = argv[i];
  59.       }
  60.       }
  61.  
  62.     if( inet_file == NULL )
  63.     Usage();
  64.  
  65.     CTGA = CTDE = CTDW = 0.0;
  66.     LAMBDACM = 0;
  67.  
  68.     init_hist();
  69.     if( (fin = fopen( inet_file, "r" )) == NULL )
  70.       {
  71.     lprintf( stderr, "cannot open '%s' for inet input\n", inet_file );
  72.     exit( 1 );
  73.       }
  74.     if( sim_file == NULL )
  75.     fout = stdout;
  76.     else if( (fout = fopen( sim_file, "w" )) == NULL )
  77.       {
  78.     lprintf( stderr, "cannot open '%s' for sim output\n", sim_file );
  79.     exit( 1 );
  80.       }
  81.  
  82.     rd_network( fin );
  83.  
  84.     (void) fprintf( fout, "| inet2sim: %s\n", inet_file );
  85.  
  86.     if( short_file ) sort_node_names( fout );
  87.  
  88.     wr_sim( fout );
  89.  
  90.     exit( 0 );
  91.     /* NOTREACHED */
  92.   }
  93.  
  94.  
  95. private void init_tab( n, ptab )
  96.   nptr  n;
  97.   nptr  *ptab;
  98.   {
  99.     static int  i = 0;
  100.  
  101.     ptab[ i++ ] = n;
  102.   }
  103.  
  104. private int cmp_nnames( n1, n2 )
  105.   nptr  *n1, *n2;
  106.   {
  107.     return( strcmp( (*n1)->nname, (*n2)->nname ) );
  108.   }
  109.  
  110.  
  111. private void sort_node_names( fp )
  112.   FILE  *fp;
  113.   {
  114.     nptr  *ntable;
  115.     int   i;
  116.  
  117.     ntable = (nptr *) Valloc( (nnodes + naliases) * sizeof( nptr ), 1 );
  118.  
  119.     walk_net( init_tab, (char *) ntable );
  120.  
  121.     qsort( ntable, nnodes + naliases, sizeof( nptr ), cmp_nnames );
  122.  
  123.     for( i = 0; i < nnodes + naliases; i++ )
  124.       {
  125.     char           buff[15];
  126.     register nptr  np = ntable[ i ];
  127.  
  128.     (void) sprintf( buff, "$%d", i + 1 );
  129.     (void) fprintf( fp, "= %s %s\n", np->nname, buff );
  130.     Vfree( np->nname );
  131.     np->nname = Valloc( strlen( buff ) + 1, 1 );
  132.     (void) strcpy( np->nname, buff );
  133.       }
  134.     Vfree( ntable );
  135.   }
  136.  
  137.  
  138. #define    PRINT    (void) fprintf
  139.  
  140. private Usage()
  141.   {
  142.     char  *prog = "inet2sim";
  143.  
  144.     PRINT( stderr, "usage: %s [-C][-2][-t][-D][-G][-c][-o file] inetfile\n",
  145.       prog );
  146.     PRINT( stderr, "  -C\tdo NOT generate node capacitance statements\n" );
  147.     PRINT( stderr, "  -2\tUse 2 terminal capacitance format (ala magic)\n" );
  148.     PRINT( stderr, "  -T\tdo NOT generate node thresholds statements\n" );
  149.     PRINT( stderr, "  -D\tdo NOT generate node User-Delays statements\n" );
  150.     PRINT( stderr, "  -G\tuse GND instead of Gnd\n" );
  151.     PRINT( stderr, "  -c\tgenerate a compressed file\n" );
  152.     exit( 1 );
  153.   }
  154.